import search from "./search/search.js";
import approved from "./approved/approved.vue";
import toBeSubmitted from "./toBeSubmitted/toBeSubmitted.vue";
import toBereviewed from "./toBereviewed/toBereviewed.vue";
// import rejected from "./rejected/rejected.vue";
import { mapGetters } from 'vuex'
import { getShopBusiness } from '@/api/shop/goods.js'
import choiceGoods from './choiceGoods.vue';
const tabName = [
    "销售中",
    "已售罄",
    "停售",
    // "已驳回",
]
export default {
    mixins: [search],
    components: {
        approved,
        toBeSubmitted,
        toBereviewed,
        choiceGoods
        // rejected
    },
    computed: {
        ...mapGetters([
            'permissions'
        ])
    },
    filters: {
        businessTypeStatus(val) {
            let obj = ''
            switch (val) {
                case '02':
                    obj = '商超'
                    break;
                case '03':
                    obj = '洗衣'
                    break;
                case '04':
                    obj = '家政'
                    break;
                case '05':
                    obj = '咖吧'
                    break;
            }
            return obj
        }

    },
    data() {
        return {
            keyName: "01",
            tab: {
                approved: "销售中",
                toBeSubmitted: "已售罄",
                toBereviewed: "停售",
                // rejected: "已驳回",
            },
            // dalShopgoodsinfo_add:false
            businessTypeList: [],
            businessType: this.$store.getters.goodsBusiness,
            userInfo: {}
        }
    },
    created() {
        // this.dalShopgoodsinfo_add = this.permissions["dal_shopgoodsinfo_add"]
    },
    mounted() {
        this.getBusiness()
    },
    methods: {
        callback(key) {
            this.keyName = key
            switch (key) {
                case '01':
                    this.$refs.approved.getList({}, 1, this.businessType, '01') //销售中列表
                    break;
                case '02':
                    this.$refs.toBeSubmitted.getList({}, 1, this.businessType, '02') //已售罄列表
                    break;
                case '00':
                    this.$refs.toBereviewed.getList({}, 1, this.businessType, '00') //停售列表
                    break;
                default:
                    break;
            }
            this.trigger()
        },
        getBusiness() {
            this.userInfo = this.$store.getters.userInfoMessage
            let businessTypeList = []
            if (this.userInfo.businessType) {
                if (this.userInfo.businessType.indexOf(',') > -1) {
                    businessTypeList = this.userInfo.businessType.split(',')

                    if (!this.$store.getters.goodsBusiness) {
                        this.businessType = businessTypeList[0]
                        this.$store.commit('SET_GOODSBUSINESS', this.businessType)
                    }
                    this.businessTypeList = businessTypeList.map(item => {
                        return {
                            businessType: item
                        }
                    })

                } else {
                    this.businessTypeList = []
                }
            }
            this.getList()
            console.log('userInfoMessage', this.$store.getters.userInfoMessage)
        },
        getList() {
            this.$refs.approved.getList({}, 1, this.businessType, '01')       //销售中列表
            this.$refs.toBeSubmitted.getList({}, 1, this.businessType, '02')  //已售罄列表
            this.$refs.toBereviewed.getList({}, 1, this.businessType, '00') //停售列表
            // this.$refs.rejected.getList() //已驳回列表
            this.trigger()
        },
        trigger() {
            this.tab.approved = `${tabName[0]}(${this.$refs.approved.page.total})`
            this.tab.toBeSubmitted = `${tabName[1]}(${this.$refs.toBeSubmitted.page.total})`
            this.tab.toBereviewed = `${tabName[2]}(${this.$refs.toBereviewed.page.total})`
            // this.tab.rejected = `${tabName[3]}(${this.$refs.rejected.pagination.total})`
        },
        addShangpin() {
            this.$router.push({ path: '/shop/goods/goods_list_add', query: { businessType: this.businessType } })
            this.$store.commit('SET_ACCESS_goodsEdit', {})
        },
        goBusiness(key) {
            this.businessType = key
            this.getList()
            this.$store.commit('SET_GOODSBUSINESS', this.businessType)
        },
        save() {
            this.$refs.choiceGoods.dialogVisible = true
            this.$refs.choiceGoods.dialogVisibleTile = '商品添加'
            this.$refs.choiceGoods.getList(this.userInfo.shopId)
        }
    }
}